package com.derbysoft.synxisadapter.dswitch3.translator;

import com.derbysoft.dswitch.dto.hotel.avail.HotelAvailCriteriaDTO;
import com.derbysoft.dswitch.dto.hotel.avail.HotelAvailRQ;
import com.derbysoft.dswitch.dto.hotel.avail.RoomStayCandidateDTO;
import com.derbysoft.dswitch.dto.hotel.reservation.ReservationRoomStayDTO;
import com.derbysoft.dswitch.remote.hotel.dto.HotelAvailRequest;
import com.derbysoft.dswitch.remote.hotel.dto.HotelReservationRequest;
import com.derbysoft.synxisadapter.dswitch2.translator.Translator;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * User: jason
 * Date: 2012-11-28
 */
@Component("ds3HotelPreviewRQTranslator")
public class HotelPreviewRQTranslator extends AbstractTranslator implements Translator<HotelReservationRequest, HotelAvailRequest, Void> {
    @Override
    public HotelAvailRequest translate(HotelReservationRequest request, Void aVoid) {
        HotelAvailRequest hotelAvailRequest = new HotelAvailRequest();
        hotelAvailRequest.setHeader(request.getHeader());
        HotelAvailRQ hotelAvailRQ = new HotelAvailRQ();
        hotelAvailRQ.setAvailCriteria(createHotelAvailRQ(request));
        hotelAvailRequest.setHotelAvailRQ(hotelAvailRQ);
        return hotelAvailRequest;
    }

    private HotelAvailCriteriaDTO createHotelAvailRQ(HotelReservationRequest request) {
        HotelAvailCriteriaDTO availCriteria = new HotelAvailCriteriaDTO();
        ArrayList<String> hotelCodes = new ArrayList<String>();
        hotelCodes.add(request.getHotelReservationRQ().getHotelReservation().getHotelCode());
        availCriteria.setHotelCodesList(hotelCodes);
        availCriteria.setLanguage(request.getHotelReservationRQ().getHotelReservation().getLanguage());
        ReservationRoomStayDTO reservationRoomStayDTO = request.getHotelReservationRQ().getHotelReservation().getRoomStaysList().get(0);

        availCriteria.setStayDateRange(reservationRoomStayDTO.getStayDateRange());
        RoomStayCandidateDTO roomStayCandidate = new RoomStayCandidateDTO();
        roomStayCandidate.setAdultCount(reservationRoomStayDTO.getAdultCount());
        roomStayCandidate.setChildCount(reservationRoomStayDTO.getChildCount());
        roomStayCandidate.setNumberOfUnits(reservationRoomStayDTO.getNumberOfUnits());
        availCriteria.setRoomStayCandidate(roomStayCandidate);
        return availCriteria;
    }
}
